/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.atm.service;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.atm.domain.ATMTransaction;

/**
 *
 * @author Abderahman
 */
@Stateless
public class ATMTransactionServiceImp implements ATMTransactionService {
@PersistenceContext(unitName = "comp-5541-atmPU")
 private EntityManager entityManager;

public void create(ATMTransaction transaction) {
        entityManager.persist(transaction);
    }

    public List<ATMTransaction> getAllDepositeNew() {
        return entityManager.createNamedQuery("ATMTransaction.findDepositAllNew", ATMTransaction.class).getResultList();
    }
    public List<ATMTransaction> getAllTransactions(Integer AccountNumber) {
//        return entityManager.createNamedQuery("ATMTransaction.findAll", ATMTransaction.class).getResultList();
    return entityManager.createNamedQuery("ATMTransaction.findByAccountID", ATMTransaction.class)
            .setParameter("accountId", AccountNumber)
            .getResultList();

    }



  public void approveTransaction(ATMTransaction transaction){
        transaction.setApproved();
        entityManager.merge(transaction);
    }

    public void rejectTransaction(ATMTransaction transaction){
        transaction.setRejected();
        entityManager.merge(transaction);
    }

    public void persist(ATMTransaction transaction) {
   //     transaction.setClientId(1);
   //     transaction.setDate("timenow");
   //     transaction.setType("Deposit");
       // transaction.setStatus("NEW");
      //  transaction.setTransactionId(1);

        entityManager.merge(transaction);
    }

}